package com.bclz.nio;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.Calendar;

public class BufferExample {


    public static void main(String[] args) {

        IntBuffer intBuffer=IntBuffer.allocate(3);
        intBuffer.put(10);
        intBuffer.put(20);
        intBuffer.put(300);
        intBuffer.flip();
        intBuffer.limit(2);
        System.out.println("limit:"+intBuffer.limit());
        while (intBuffer.hasRemaining()){

            System.out.println("Position: "+intBuffer.position()+" Value:"+intBuffer.get());

        }
//        intBuffer.clear();
//        intBuffer.reset();
//        System.out.println(intBuffer.get());

        //ByteBuffer支持类型的put set,放入取出顺序一定要一致,否则结构会发生变化
        ByteBuffer byteBuffer=ByteBuffer.allocate(1024);
        byteBuffer.putChar('张');
        byteBuffer.putInt(123);
        byteBuffer.putFloat(12.1f);
        byteBuffer.flip();
        System.out.println(byteBuffer.getChar());
        System.out.println(byteBuffer.getInt());
        System.out.println(byteBuffer.getFloat());
    }

}
